CFLAGS=-g -Wall -fPIC
CXXFLAGS=-g -Wall -std=c++11
INCPATH=-I.
#LIBS=-L. -lmemhook

DLL=libmemhook.so 
DLL_SRCS=libmemhook.c
DLL_OBJS=$(DLL_SRCS:.c=.o)


APP=malloc_hook_test
SRCS=$(wildcard *.cpp)
OBJS=$(SRCS:.cpp=.o)

STUB=memtest
STUB_SRCS=memtest.c
STUB_OBJS=$(STUB_SRCS:.c=.o)


all: $(DLL) $(STUB) ${APP}

$(DLL): $(DLL_OBJS)
	$(CC) -shared -fPIC -ldl -o $@ $^
	
$(STUB): $(STUB_OBJS)
	$(CC) $(CFLAGS) $(INCPATH) -o $@ $^ $(LIBS)

${APP}: ${OBJS}
	$(CXX) $(CXXFLAGS) $(INCPATH) -o $@ $^ $(LIBS)

.cpp.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
	$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<	

clean:
	rm -f *.o *.log $(APP) $(DLL) $(STUB)

test: all
	./${APP}

